package com.glory.erp.invoice.store.action;

import java.util.List;

import com.glory.erp.invoice.store.service.StoreService;
import com.glory.erp.invoice.store.bean.Store;
import com.glory.erp.invoice.store.bean.StoreQuery;
import com.glory.erp.auth.base.BaseAction;
import com.glory.erp.auth.emp.bean.Emp;
import com.glory.erp.auth.emp.service.EmpService;

public class StoreAction extends BaseAction{
	
	public Store store = new Store();
	public StoreQuery storeQuery = new StoreQuery();

	private StoreService storeService;
	
	private EmpService empService;
	
	public void setEmpService(EmpService empService) {
		this.empService = empService;
	}

	public void setStoreService(StoreService storeService) {
		this.storeService = storeService;
	}

	/**
	 * 
	 * @Description: 仓库列表展示
	 * @Title: list
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年6月9日 上午11:54:27
	 * @throws
	 */
	public String list(){
		setDataTotal(storeService.getCount(storeQuery));
		List<Store> storeList = storeService.findAll(storeQuery,pageNum,pageCount);
		put("storeList", storeList);
		List<Emp> empList = empService.findAll();
		put("empList", empList);
		return LIST;
	}

	/**
	 * 
	 * @Description: 跳转至仓库新增、修改页面
	 * @Title: addView
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年6月9日 上午11:55:08
	 * @throws
	 */
	public String addView(){
		List<Emp> empList = empService.findByDept(getLogin().getDept().getUuid());
		put("empList", empList);
		if(store.getUuid()!=null){
			store = storeService.findById(store.getUuid());
		}
		return ADD;
	}

	/**
	 * 
	 * @Description: 新增、修改操作
	 * @Title: saveAndUpdate
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年6月9日 上午11:55:30
	 * @throws
	 */
	public String saveAndUpdate(){
		if(store.getUuid() == null){
			storeService.save(store);
		}else{
			storeService.update(store);
		}
		return TO_LIST;
	}

	/**
	 * 
	 * @Description: 删除仓库
	 * @Title: delete
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年6月9日 上午11:55:48
	 * @throws
	 */
	public String delete(){
		storeService.delete(store);
		return TO_LIST;
	}
}